package com.zxg.zbc.dal.dataobject.concurrent;

import java.util.Date;

public class Lock {

  private Long           id;
  private ConcurrentType type;
  private LockStatus     status;
  private String         host;
  private String         descr;
  private Date           lockTime;
  private Date           gmtCreated;
  private Date           gmtModified;

  private Integer        timeout = 600;

  public Lock() {

  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public Integer getType() {
    return type.getValue();
  }

  public void setType(Integer type) {
    this.type = ConcurrentType.getType(type);
  }

  public void setType(ConcurrentType type) {
    this.type = type;
  }

  public Integer getStatus() {
    return status.getValue();
  }

  public void setStatus(Integer status) {
    this.status = LockStatus.lockValue(status.equals(1));
  }

  public void setStatus(LockStatus status) {
    this.status = status;
  }

  public String getHost() {
    return host;
  }

  public void setHost(String host) {
    this.host = host;
  }

  public String getDescr() {
    return descr;
  }

  public void setDescr(String descr) {
    this.descr = descr;
  }

  public Date getLockTime() {
    return lockTime;
  }

  public void setLockTime(Date lockTime) {
    this.lockTime = lockTime;
  }

  public Date getGmtCreated() {
    return gmtCreated;
  }

  public void setGmtCreated(Date gmtCreated) {
    this.gmtCreated = gmtCreated;
  }

  public Date getGmtModified() {
    return gmtModified;
  }

  public void setGmtModified(Date gmtModified) {
    this.gmtModified = gmtModified;
  }

  public Integer getTimeout() {
    return timeout;
  }

  public void setTimeout(Integer timeout) {
    this.timeout = timeout;
  }

  public static enum ConcurrentType {

    DAILY_JOB(1), TMC(2), SYN_ITEM(3);
    private Integer value;

    private ConcurrentType(Integer value) {
      this.value = value;
    }

    public Integer getValue() {
      return value;
    }

    public void setValue(Integer value) {
      this.value = value;
    }

    public static ConcurrentType getType(Integer value) {
      if (value.equals(1))
        return DAILY_JOB;
      if (value.equals(2))
        return TMC;
      if (value.equals(3))
        return SYN_ITEM;

      return null;

    }

  }

  public static enum LockStatus {
    LOCKED(1), UNLOCKED(0);
    private Integer value;

    private LockStatus(Integer value) {
      this.value = value;
    }

    public Integer getValue() {
      return value;
    }

    public void setValue(Integer value) {
      this.value = value;
    }

    public static LockStatus lockValue(boolean locked) {
      if (locked)
        return LOCKED;
      else
        return UNLOCKED;
    }
  }
}
